package com.zhihaoliang.baseframe.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.zhihaoliang.baseframe.R;
import com.zhihaoliang.baseframe.model.Product;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //把产品列表的Fragment加入到Activity中如果是第一次加入的话
        if(savedInstanceState == null){
            ProductListFragment productListFragment = new ProductListFragment();
            getSupportFragmentManager().
                    beginTransaction().
                    add(R.id.fragment_container,productListFragment,ProductListFragment.TAG).commit();
        }
    }

    /**
     * 显示产品的详情
     */
    public void show(Product product){
        ProductFragment productFragment = ProductFragment.forProduct(product.getId());
        getSupportFragmentManager().beginTransaction().
                addToBackStack("product").
                replace(R.id.fragment_container,productFragment,ProductFragment.TAG).commit();
    }
}
